#ifndef BOARD_H
#define BOARD_H

#include "core/subject.h"

#include <QVector>
#include <QString>

class Tile;

enum Direction { UP, DOWN, LEFT, RIGHT };

class Board : public Subject
{
public:

    Board(int dimension);
    Board(const Board& other);
    // 删除棋盘
    ~Board();
    // 初始化棋盘并保留两个棋子
    void reset();

    Tile* getTile(int i, int j);
    int getDimension() const { return dimension; }  //获取棋盘的边长
    //将棋盘的棋子向direction方向移动
    void move(Direction direction);
    bool full() const;  //查看当前棋盘是否放满
    int getPointsScoredLastRound() const { return pointsScoredLastRound; }
    bool isTileCollisionLastRound() const { return tileCollisionLastRound; }
    // is there still a move possible
    bool movePossible() const;

private:
    QVector<QVector<Tile*> > board;  //创建方格图
    int dimension;  //是用来表示行数/列数的吗？

    // 创建空棋盘
    void init();
    // 生成一个棋子的随机坐标(x, y)
    QVector<int> freePosition();
    // returns true if the current state of the board is different from the argument
    bool changed(Board& other) const;

    bool inbounds(int i, int j);
    // changes state!! (tileCollision & pointsScoredLastRound)
    //水平移动整个棋盘
    void moveHorizontally(int i, int j, Direction dir);
    //竖直移动整个棋盘
    void moveVertically(int i, int j, Direction dir);
    //处理棋子碰撞发生的情况
    void handleCollision(int i, int j);

    // some reinitalisation for the next round
    void prepareForNextMove();

    int pointsScoredLastRound;  //当前得分
    bool tileCollisionLastRound;  //是什么？
};

#endif // BOARD_H
